// components/playlist/playlist.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    playlist: {
      type: Object
    }
  },
  
  // 监听数据
  observers: {
    ['playlist.playCount'](count){
      let _playCount = this._tranPlayNum(count)
      this.setData({
        playCount: _playCount
      })
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    playCount: 0
  },

  /**
   * 组件的方法列表
   */
  methods: {
    _tranPlayNum(count, decimal){
      let _count = count.toFixed(0)
      if (_count.length <= 5) {
        return _count
      } else if (_count.length > 5 && _count.length <= 8) {
        let count1 = (_count / 10000).toString().split('.')[0]
        let count2 = (_count / 10000).toString().split('.')[1].substring(0,2)
        return count1 + '.' + count2 + '万'
      } else if (_count.length > 8) {
        let count1 = (_count / 100000000).toString().split('.')[0]
        let count2 = (_count / 100000000).toString().split('.')[1].substring(0, 2)
        return count1 + '.' + count2 + '亿'
      }
    },
    getMusicList() {
      wx.navigateTo({
        url: `../../pages/musiclist/musiclist?playlistId=${this.properties.playlist.id}`,
      })
    },
  }
})
